package button;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2016/6/22.
 */
public class TomPreference {
        private static final String PREF_FILE_NAME = "scanner";
        private static final String IS_SOUND_ON = "sound";
        private static final String IS_VIBRATE_ON = "vibrate";

        private static TomPreference self;

        public static synchronized TomPreference getInstance(Context context){
            if(self == null) self = new TomPreference(context);
            return self;
        }

        private SharedPreferences sharedPreferences;
        private SharedPreferences.Editor editor;

        public TomPreference(Context context){
            sharedPreferences = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
            editor = sharedPreferences.edit();
        }

        public void setIsSoundOn(boolean on){
            editor.putBoolean(IS_SOUND_ON,on);
            editor.commit();
        }

        public void getIsSoundOn(boolean  defaultOn){
            sharedPreferences.getBoolean(IS_SOUND_ON,defaultOn);
        }
        public void setIsVibrateOn(boolean on){
            editor.putBoolean(IS_VIBRATE_ON,on);
            editor.commit();
        }

        public void getIsVibrateOn(boolean  defaultOn){
            sharedPreferences.getBoolean(IS_VIBRATE_ON,defaultOn);
        }
    }

